package com.example.borui.partpositionproject;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.example.borui.partpositionproject.partpisition.base.IConfig;
import com.example.borui.partpositionproject.partpisition.base.IPartPositionView;
import com.example.borui.partpositionproject.partpisition.view.IPartPositionBean;
import com.example.borui.partpositionproject.simple.adapter.SimpleAdapter;
import com.example.borui.partpositionproject.simple.bean.DataBean;
import com.example.borui.partpositionproject.simple.utils.Utils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity implements IPartPositionView {

    RecyclerView mRecyclerView;

    private SimpleAdapter simpleAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);

        try{
            GridLayoutManager gridLayoutManager = new GridLayoutManager(this, IConfig.CLUMS, GridLayoutManager.VERTICAL, false);
            mRecyclerView.setLayoutManager(gridLayoutManager);
        }catch (Exception e){
            System.out.println("wo shi shen" + e.getMessage());
        }

        initSimpleData();
    }

    private void initSimpleData() {
        List<DataBean> dataBeans = Utils.buildSimpleDatas();
        simpleAdapter = new SimpleAdapter(this, this);
        mRecyclerView.setAdapter(simpleAdapter);

        List<IPartPositionBean> mDatas = new ArrayList<>();
        mDatas.addAll(dataBeans);
        simpleAdapter.updatePositionItems(mDatas);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        simpleAdapter.onDestory();
    }
}
